/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;


/**
 *
 * @author Team 3502
 */
public class DriveToTargetTestPics extends CommandBase {
    private double targetXo;
    private double turndist;

    public DriveToTargetTestPics() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(drive);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        //targetXo = drive.findtarget(); //the initial x pixel of the highest hoop
        System.out.print("targetXo = " + targetXo);
        drive.initsensors();
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        //turndist = drive.readencoders();
        if (targetXo < -0.1){
            System.out.println("Target is to the left");
            //need way to convert between encoder distance and pixels distance........
            //for now, just have the robot turn 8 inches (1 wheel revolution)
            if (turndist <= 8.0){
                drive.driveWithJoy(0, -0.4);
            }
            else {
                drive.driveWithJoy(0, 0);
            }
        }
        else if (targetXo > 0.1){
            System.out.println("Target is to the right");
            if (turndist <= 8.0){
                drive.driveWithJoy(0, 0.4);
            }
            else {
                drive.driveWithJoy(0, 0);
            }
        }
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        drive.initsensors();
    }
}